package com.ymttest.business.service.productdata.service;

import java.io.File;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymatou.iapi.productquery.service.GetProductInfoByProductIdCall;
import com.ymttest.utils.FileUtil;
import com.ymttest.utils.compare.CompareHelper;
import com.ymttest.utils.compare.LogPathConf;
import com.ymttest.utils.compare.LoggerHelper;
import com.ymttest.utils.compare.LoggerInterface;

public class CreateProduct2 {

	public static void main(String args[]) {
		LogPathConf logPathConf = new LogPathConf(true);
		LoggerInterface logger = new LoggerHelper(logPathConf);
		CompareHelper compareHelper = new CompareHelper(logger, 5);
		String priceFile = System.getProperty("user.dir") + File.separator + "resource" + File.separator + "CompareData"
				+ File.separator + "productId.txt";

		List<String> priceFileList = FileUtil.readFileAsLine(priceFile);

		for (String productId : priceFileList) {
			JSONObject prodDetail = new GetProductInfoByProductIdCall().callAndGetReturnData(productId);

			
			try {
				JSONArray catalogAry = prodDetail.getJSONObject("Data").getJSONObject("Product").getJSONArray("CatalogList");
				for (int i=0;i<catalogAry.length();i++){
					String catalogId = catalogAry.getJSONObject(i).getString("CatalogId");
					double price = catalogAry.getJSONObject(i).getDouble("Price");
					String productName = prodDetail.getJSONObject("Data").getJSONObject("Product").getString("Title");
					logger.comment(catalogId+","+price+","+productName);
				}
				
			} catch (JSONException e) {
				logger.comment("Error,productid:"+productId);
			}

			
		}
	}

}
